package com.inei.eea2014.tools;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

import org.apache.http.protocol.HTTP;
import org.xmlpull.v1.XmlSerializer;

import com.inei.eea2014.controller.Capitulo1Controller;
import com.inei.eea2014.controller.Capitulo2Controller;
import com.inei.eea2014.controller.Capitulo3Controller;
import com.inei.eea2014.controller.Capitulo4Controller;
import com.inei.eea2014.controller.CaratulaController;
import com.inei.eea2014.controller.EntrevistaController;
import com.inei.eea2014.controller.JustificacionController;
import com.inei.eea2014.model.entity.Capitulo1;
import com.inei.eea2014.model.entity.Capitulo2;
import com.inei.eea2014.model.entity.Capitulo3;
import com.inei.eea2014.model.entity.Capitulo4;
import com.inei.eea2014.model.entity.Caratula;
import com.inei.eea2014.model.entity.Entrevista;
import com.inei.eea2014.model.entity.Justificacion;

import android.content.Context;
import android.os.Environment;
import android.util.Xml;

public class Exportar {

	private Context context;

	public Exportar(Context context) {
		this.context = context;
	}

	public boolean xml(String RUC, String USUARIO) {
		File file = null;
		File ruta = null;
		try {
			File root = Environment.getExternalStorageDirectory();
			ruta = new File(root, "/EEA2014/");
			if (!ruta.exists()) {
				ruta.mkdirs();
			}
			file = new File(ruta, RUC + ".xml");
			FileOutputStream fos = new FileOutputStream(file);
			XmlSerializer xml = Xml.newSerializer();
			xml.setOutput(fos, HTTP.UTF_8);
			xml.startDocument(HTTP.UTF_8, true);

			xml.startTag("", "script");

			// CARATULA
			CaratulaController carCon = new CaratulaController(context);
			Caratula car = new Caratula(RUC, USUARIO);
			car = carCon.CarObtener(car);
			if (car != null) {
				xml.startTag("", "C0000");
				if (car.getC0000_001_01_T() != null
						&& !car.getC0000_001_01_T().equals("")) {
					xml.startTag("", "C0000_001_01_T");
					xml.text(car.getC0000_001_01_T());
					xml.endTag("", "C0000_001_01_T");
				}
				if (car.getC0000_001_02_T() != null
						&& !car.getC0000_001_02_T().equals("")) {
					xml.startTag("", "C0000_001_02_T");
					xml.text(car.getC0000_001_02_T());
					xml.endTag("", "C0000_001_02_T");
				}
				if (car.getC0000_001_03_T() != null
						&& !car.getC0000_001_03_T().equals("")) {
					xml.startTag("", "C0000_001_03_T");
					xml.text(car.getC0000_001_03_T());
					xml.endTag("", "C0000_001_03_T");
				}
				if (car.getC0000_001_04_T() != null
						&& !car.getC0000_001_04_T().equals("")) {
					xml.startTag("", "C0000_001_04_T");
					xml.text(car.getC0000_001_04_T());
					xml.endTag("", "C0000_001_04_T");
				}
				if (car.getC0000_001_05_T() != null
						&& !car.getC0000_001_05_T().equals("")) {
					xml.startTag("", "C0000_001_05_T");
					xml.text(car.getC0000_001_05_T());
					xml.endTag("", "C0000_001_05_T");
				}
				if (car.getC0000_001_06_T() != null
						&& !car.getC0000_001_06_T().equals("0000")) {
					xml.startTag("", "C0000_001_06_T");
					xml.text(car.getC0000_001_06_T());
					xml.endTag("", "C0000_001_06_T");
				}
				xml.endTag("", "C0000");
			}

			// CAPITULO 1
			Capitulo1Controller cap1Con = new Capitulo1Controller(context);
			Capitulo1 cap1 = new Capitulo1(RUC, USUARIO);
			cap1 = cap1Con.Cap01Obtener(cap1);
			if (cap1 != null) {
				xml.startTag("", "C0001");
				if (cap1.getC0001_001_01_T() != null
						&& !cap1.getC0001_001_01_T().equals("")) {
					xml.startTag("", "C0001_001_01_T");
					xml.text(cap1.getC0001_001_01_T());
					xml.endTag("", "C0001_001_01_T");
				}
				if (cap1.getC0001_002_01_T() != null
						&& !cap1.getC0001_002_01_T().equals("")) {
					xml.startTag("", "C0001_002_01_T");
					xml.text(cap1.getC0001_002_01_T());
					xml.endTag("", "C0001_002_01_T");
				}
				if (cap1.getC0001_003_01_T() != null
						&& !cap1.getC0001_003_01_T().equals("")) {
					xml.startTag("", "C0001_003_01_T");
					xml.text(cap1.getC0001_003_01_T());
					xml.endTag("", "C0001_003_01_T");
				}
				if (cap1.getC0001_004_01_T() != null
						&& !cap1.getC0001_004_01_T().equals("")) {
					xml.startTag("", "C0001_004_01_T");
					xml.text(cap1.getC0001_004_01_T());
					xml.endTag("", "C0001_004_01_T");
				}
				if (cap1.getC0001_005_01_T() != null
						&& !cap1.getC0001_005_01_T().equals("")) {
					xml.startTag("", "C0001_005_01_T");
					xml.text(cap1.getC0001_005_01_T());
					xml.endTag("", "C0001_005_01_T");
				}
				if (cap1.getC0001_006_01_T() != null
						&& !cap1.getC0001_006_01_T().equals("")) {
					xml.startTag("", "C0001_006_01_T");
					xml.text(cap1.getC0001_006_01_T());
					xml.endTag("", "C0001_006_01_T");
				}
				if (cap1.getC0001_007_01_T() != null
						&& !cap1.getC0001_007_01_T().equals("0")) {
					xml.startTag("", "C0001_007_01_T");
					xml.text(cap1.getC0001_007_01_T());
					xml.endTag("", "C0001_007_01_T");
				}
				if (cap1.getC0001_008_01_T() != null
						&& !cap1.getC0001_008_01_T().equals("")) {
					xml.startTag("", "C0001_008_01_T");
					xml.text(cap1.getC0001_008_01_T());
					xml.endTag("", "C0001_008_01_T");
				}
				if (cap1.getC0001_009_01_T() != null
						&& !cap1.getC0001_009_01_T().equals("")) {
					xml.startTag("", "C0001_009_01_T");
					xml.text(cap1.getC0001_009_01_T());
					xml.endTag("", "C0001_009_01_T");
				}
				if (cap1.getC0001_010_01_T() != null
						&& !cap1.getC0001_010_01_T().equals("")) {
					xml.startTag("", "C0001_010_01_T");
					xml.text(cap1.getC0001_010_01_T());
					xml.endTag("", "C0001_010_01_T");
				}
				if (cap1.getC0001_011_01_T() != null
						&& !cap1.getC0001_011_01_T().equals("")) {
					xml.startTag("", "C0001_011_01_T");
					xml.text(cap1.getC0001_011_01_T());
					xml.endTag("", "C0001_011_01_T");
				}
				if (cap1.getC0001_012_01_T() != null
						&& !cap1.getC0001_012_01_T().equals("")) {
					xml.startTag("", "C0001_012_01_T");
					xml.text(cap1.getC0001_012_01_T());
					xml.endTag("", "C0001_012_01_T");
				}
				if (cap1.getC0001_013_01_T() != null
						&& !cap1.getC0001_013_01_T().equals("")) {
					xml.startTag("", "C0001_013_01_T");
					xml.text(cap1.getC0001_013_01_T());
					xml.endTag("", "C0001_013_01_T");
				}
				if (cap1.getC0001_014_01_T() != null
						&& !cap1.getC0001_014_01_T().equals("")) {
					xml.startTag("", "C0001_014_01_T");
					xml.text(cap1.getC0001_014_01_T());
					xml.endTag("", "C0001_014_01_T");
				}
				if (cap1.getC0001_015_01_T() != null
						&& !cap1.getC0001_015_01_T().equals("")) {
					xml.startTag("", "C0001_015_01_T");
					xml.text(cap1.getC0001_015_01_T());
					xml.endTag("", "C0001_015_01_T");
				}
				if (cap1.getC0001_016_01_T() != null
						&& !cap1.getC0001_016_01_T().equals("")) {
					xml.startTag("", "C0001_016_01_T");
					xml.text(cap1.getC0001_016_01_T());
					xml.endTag("", "C0001_016_01_T");
				}
				if (cap1.getC0001_017_01_T() != null
						&& !cap1.getC0001_017_01_T().equals("")) {
					xml.startTag("", "C0001_017_01_T");
					xml.text(cap1.getC0001_017_01_T());
					xml.endTag("", "C0001_017_01_T");
				}
				if (cap1.getC0001_018_01_T() != null
						&& !cap1.getC0001_018_01_T().equals("")) {
					xml.startTag("", "C0001_018_01_T");
					xml.text(cap1.getC0001_018_01_T());
					xml.endTag("", "C0001_018_01_T");
				}
				if (cap1.getC0001_019_01_T() != null
						&& !cap1.getC0001_019_01_T().equals("00")) {
					xml.startTag("", "C0001_019_01_T");
					xml.text(cap1.getC0001_019_01_T());
					xml.endTag("", "C0001_019_01_T");
				}
				if (cap1.getC0001_020_01_T() != null
						&& !cap1.getC0001_020_01_T().equals("00")) {
					xml.startTag("", "C0001_020_01_T");
					xml.text(cap1.getC0001_020_01_T());
					xml.endTag("", "C0001_020_01_T");
				}
				if (cap1.getC0001_021_01_T() != null
						&& !cap1.getC0001_021_01_T().equals("00")) {
					xml.startTag("", "C0001_021_01_T");
					xml.text(cap1.getC0001_021_01_T());
					xml.endTag("", "C0001_021_01_T");
				}
				if (cap1.getC0001_022_01_T() != null
						&& !cap1.getC0001_022_01_T().equals("0000")) {
					xml.startTag("", "C0001_022_01_T");
					xml.text(cap1.getC0001_022_01_T());
					xml.endTag("", "C0001_022_01_T");
				}
				if (cap1.getC0001_023_01_T() != null
						&& !cap1.getC0001_023_01_T().equals("00000")) {
					xml.startTag("", "C0001_023_01_T");
					xml.text(cap1.getC0001_023_01_T());
					xml.endTag("", "C0001_023_01_T");
				}
				if (cap1.getC0001_024_01_T() != null
						&& !cap1.getC0001_024_01_T().equals("00")) {
					xml.startTag("", "C0001_024_01_T");
					xml.text(cap1.getC0001_024_01_T());
					xml.endTag("", "C0001_024_01_T");
				}
				if (cap1.getC0001_029_01_T() != null
						&& !cap1.getC0001_029_01_T().equals("")) {
					xml.startTag("", "C0001_029_01_T");
					xml.text(cap1.getC0001_029_01_T());
					xml.endTag("", "C0001_029_01_T");
				}
				if (cap1.getC0001_031_01_T() != null
						&& !cap1.getC0001_031_01_T().equals("")) {
					xml.startTag("", "C0001_031_01_T");
					xml.text(cap1.getC0001_031_01_T());
					xml.endTag("", "C0001_031_01_T");
				}
				if (cap1.getC0001_032_01_T() != null
						&& !cap1.getC0001_032_01_T().equals("")) {
					xml.startTag("", "C0001_032_01_T");
					xml.text(cap1.getC0001_032_01_T());
					xml.endTag("", "C0001_032_01_T");
				}
				if (cap1.getC0001_033_01_T() != null
						&& !cap1.getC0001_033_01_T().equals("")) {
					xml.startTag("", "C0001_033_01_T");
					xml.text(cap1.getC0001_033_01_T());
					xml.endTag("", "C0001_033_01_T");
				}
				if (cap1.getC0001_034_01_T() != null
						&& !cap1.getC0001_034_01_T().equals("")) {
					xml.startTag("", "C0001_034_01_T");
					xml.text(cap1.getC0001_034_01_T());
					xml.endTag("", "C0001_034_01_T");
				}
				xml.endTag("", "C0001");
			}

			// CAPITULO 2
			Capitulo2Controller cap2Con = new Capitulo2Controller(context);
			Capitulo2 cap2 = new Capitulo2(RUC, USUARIO);
			cap2 = cap2Con.Cap02Obtener(cap2);
			if (cap2 != null) {
				xml.startTag("", "C0002");
				if (cap2.getC0002_001_01_N() != 0) {
					xml.startTag("", "C0002_001_01_N");
					xml.text(cap2.getC0002_001_01_N() + "");
					xml.endTag("", "C0002_001_01_N");
				}
				if (cap2.getC0002_002_01_N() != 0) {
					xml.startTag("", "C0002_002_01_N");
					xml.text(cap2.getC0002_002_01_N() + "");
					xml.endTag("", "C0002_002_01_N");
				}
				if (cap2.getC0002_003_01_N() != 0) {
					xml.startTag("", "C0002_003_01_N");
					xml.text(cap2.getC0002_003_01_N() + "");
					xml.endTag("", "C0002_003_01_N");
				}
				if (cap2.getC0002_004_01_N() != 0) {
					xml.startTag("", "C0002_004_01_N");
					xml.text(cap2.getC0002_004_01_N() + "");
					xml.endTag("", "C0002_004_01_N");
				}
				if (cap2.getC0002_005_01_N() != 0) {
					xml.startTag("", "C0002_005_01_N");
					xml.text(cap2.getC0002_005_01_N() + "");
					xml.endTag("", "C0002_005_01_N");
				}
				if (cap2.getC0002_006_01_N() != 0) {
					xml.startTag("", "C0002_006_01_N");
					xml.text(cap2.getC0002_006_01_N() + "");
					xml.endTag("", "C0002_006_01_N");
				}
				if (cap2.getC0002_007_01_N() != 0) {
					xml.startTag("", "C0002_007_01_N");
					xml.text(cap2.getC0002_007_01_N() + "");
					xml.endTag("", "C0002_007_01_N");
				}
				if (cap2.getC0002_008_01_N() != 0) {
					xml.startTag("", "C0002_008_01_N");
					xml.text(cap2.getC0002_008_01_N() + "");
					xml.endTag("", "C0002_008_01_N");
				}
				if (cap2.getC0002_009_01_N() != 0) {
					xml.startTag("", "C0002_009_01_N");
					xml.text(cap2.getC0002_009_01_N() + "");
					xml.endTag("", "C0002_009_01_N");
				}
				if (cap2.getC0002_010_01_N() != 0) {
					xml.startTag("", "C0002_010_01_N");
					xml.text(cap2.getC0002_010_01_N() + "");
					xml.endTag("", "C0002_010_01_N");
				}
				if (cap2.getC0002_011_01_N() != 0) {
					xml.startTag("", "C0002_011_01_N");
					xml.text(cap2.getC0002_011_01_N() + "");
					xml.endTag("", "C0002_011_01_N");
				}
				if (cap2.getC0002_012_01_N() != 0) {
					xml.startTag("", "C0002_012_01_N");
					xml.text(cap2.getC0002_012_01_N() + "");
					xml.endTag("", "C0002_012_01_N");
				}
				if (cap2.getC0002_013_01_N() != 0) {
					xml.startTag("", "C0002_013_01_N");
					xml.text(cap2.getC0002_013_01_N() + "");
					xml.endTag("", "C0002_013_01_N");
				}
				xml.endTag("", "C0002");
			}

			// CAPITULO 3
			Capitulo3Controller cap3Con = new Capitulo3Controller(context);
			Capitulo3 cap3 = new Capitulo3(RUC, USUARIO);
			cap3 = cap3Con.Cap03Obtener(cap3);
			if (cap3 != null) {
				xml.startTag("", "C0003");
				if (cap3.getC0003_001_01_N() != 0) {
					xml.startTag("", "C0003_001_01_N");
					xml.text(cap3.getC0003_001_01_N() + "");
					xml.endTag("", "C0003_001_01_N");
				}
				if (cap3.getC0003_001_02_N() != 0) {
					xml.startTag("", "C0003_001_02_N");
					xml.text(cap3.getC0003_001_02_N() + "");
					xml.endTag("", "C0003_001_02_N");
				}
				if (cap3.getC0003_001_03_N() != 0) {
					xml.startTag("", "C0003_001_03_N");
					xml.text(cap3.getC0003_001_03_N() + "");
					xml.endTag("", "C0003_001_03_N");
				}
				if (cap3.getC0003_001_04_N() != 0) {
					xml.startTag("", "C0003_001_04_N");
					xml.text(cap3.getC0003_001_04_N() + "");
					xml.endTag("", "C0003_001_04_N");
				}
				if (cap3.getC0003_002_01_N() != 0) {
					xml.startTag("", "C0003_002_01_N");
					xml.text(cap3.getC0003_002_01_N() + "");
					xml.endTag("", "C0003_002_01_N");
				}
				if (cap3.getC0003_002_02_N() != 0) {
					xml.startTag("", "C0003_002_02_N");
					xml.text(cap3.getC0003_002_02_N() + "");
					xml.endTag("", "C0003_002_02_N");
				}
				if (cap3.getC0003_002_03_N() != 0) {
					xml.startTag("", "C0003_002_03_N");
					xml.text(cap3.getC0003_002_03_N() + "");
					xml.endTag("", "C0003_002_03_N");
				}
				if (cap3.getC0003_002_04_N() != 0) {
					xml.startTag("", "C0003_002_04_N");
					xml.text(cap3.getC0003_002_04_N() + "");
					xml.endTag("", "C0003_002_04_N");
				}
				if (cap3.getC0003_003_01_N() != 0) {
					xml.startTag("", "C0003_003_01_N");
					xml.text(cap3.getC0003_003_01_N() + "");
					xml.endTag("", "C0003_003_01_N");
				}
				if (cap3.getC0003_003_02_N() != 0) {
					xml.startTag("", "C0003_003_02_N");
					xml.text(cap3.getC0003_003_02_N() + "");
					xml.endTag("", "C0003_003_02_N");
				}
				if (cap3.getC0003_003_03_N() != 0) {
					xml.startTag("", "C0003_003_03_N");
					xml.text(cap3.getC0003_003_03_N() + "");
					xml.endTag("", "C0003_003_03_N");
				}
				if (cap3.getC0003_003_04_N() != 0) {
					xml.startTag("", "C0003_003_04_N");
					xml.text(cap3.getC0003_003_04_N() + "");
					xml.endTag("", "C0003_003_04_N");
				}
				if (cap3.getC0003_004_01_N() != 0) {
					xml.startTag("", "C0003_004_01_N");
					xml.text(cap3.getC0003_004_01_N() + "");
					xml.endTag("", "C0003_004_01_N");
				}
				if (cap3.getC0003_004_02_N() != 0) {
					xml.startTag("", "C0003_004_02_N");
					xml.text(cap3.getC0003_004_02_N() + "");
					xml.endTag("", "C0003_004_02_N");
				}
				if (cap3.getC0003_004_03_N() != 0) {
					xml.startTag("", "C0003_004_03_N");
					xml.text(cap3.getC0003_004_03_N() + "");
					xml.endTag("", "C0003_004_03_N");
				}
				if (cap3.getC0003_004_04_N() != 0) {
					xml.startTag("", "C0003_004_04_N");
					xml.text(cap3.getC0003_004_04_N() + "");
					xml.endTag("", "C0003_004_04_N");
				}
				if (cap3.getC0003_005_01_N() != 0) {
					xml.startTag("", "C0003_005_01_N");
					xml.text(cap3.getC0003_005_01_N() + "");
					xml.endTag("", "C0003_005_01_N");
				}
				if (cap3.getC0003_005_02_N() != 0) {
					xml.startTag("", "C0003_005_02_N");
					xml.text(cap3.getC0003_005_02_N() + "");
					xml.endTag("", "C0003_005_02_N");
				}
				if (cap3.getC0003_005_03_N() != 0) {
					xml.startTag("", "C0003_005_03_N");
					xml.text(cap3.getC0003_005_03_N() + "");
					xml.endTag("", "C0003_005_03_N");
				}
				if (cap3.getC0003_005_04_N() != 0) {
					xml.startTag("", "C0003_005_04_N");
					xml.text(cap3.getC0003_005_04_N() + "");
					xml.endTag("", "C0003_005_04_N");
				}
				if (cap3.getC0003_006_01_N() != 0) {
					xml.startTag("", "C0003_006_01_N");
					xml.text(cap3.getC0003_006_01_N() + "");
					xml.endTag("", "C0003_006_01_N");
				}
				if (cap3.getC0003_006_02_N() != 0) {
					xml.startTag("", "C0003_006_02_N");
					xml.text(cap3.getC0003_006_02_N() + "");
					xml.endTag("", "C0003_006_02_N");
				}
				if (cap3.getC0003_006_03_N() != 0) {
					xml.startTag("", "C0003_006_03_N");
					xml.text(cap3.getC0003_006_03_N() + "");
					xml.endTag("", "C0003_006_03_N");
				}
				if (cap3.getC0003_006_04_N() != 0) {
					xml.startTag("", "C0003_006_04_N");
					xml.text(cap3.getC0003_006_04_N() + "");
					xml.endTag("", "C0003_006_04_N");
				}
				if (cap3.getC0003_007_01_N() != 0) {
					xml.startTag("", "C0003_007_01_N");
					xml.text(cap3.getC0003_007_01_N() + "");
					xml.endTag("", "C0003_007_01_N");
				}
				if (cap3.getC0003_007_02_N() != 0) {
					xml.startTag("", "C0003_007_02_N");
					xml.text(cap3.getC0003_007_02_N() + "");
					xml.endTag("", "C0003_007_02_N");
				}
				if (cap3.getC0003_007_03_N() != 0) {
					xml.startTag("", "C0003_007_03_N");
					xml.text(cap3.getC0003_007_03_N() + "");
					xml.endTag("", "C0003_007_03_N");
				}
				if (cap3.getC0003_007_04_N() != 0) {
					xml.startTag("", "C0003_007_04_N");
					xml.text(cap3.getC0003_007_04_N() + "");
					xml.endTag("", "C0003_007_04_N");
				}
				if (cap3.getC0003_008_01_N() != 0) {
					xml.startTag("", "C0003_008_01_N");
					xml.text(cap3.getC0003_008_01_N() + "");
					xml.endTag("", "C0003_008_01_N");
				}
				if (cap3.getC0003_008_02_N() != 0) {
					xml.startTag("", "C0003_008_02_N");
					xml.text(cap3.getC0003_008_02_N() + "");
					xml.endTag("", "C0003_008_02_N");
				}
				if (cap3.getC0003_008_03_N() != 0) {
					xml.startTag("", "C0003_008_03_N");
					xml.text(cap3.getC0003_008_03_N() + "");
					xml.endTag("", "C0003_008_03_N");
				}
				if (cap3.getC0003_008_04_N() != 0) {
					xml.startTag("", "C0003_008_04_N");
					xml.text(cap3.getC0003_008_04_N() + "");
					xml.endTag("", "C0003_008_04_N");
				}
				if (cap3.getC0003_009_01_N() != 0) {
					xml.startTag("", "C0003_009_01_N");
					xml.text(cap3.getC0003_009_01_N() + "");
					xml.endTag("", "C0003_009_01_N");
				}
				if (cap3.getC0003_009_02_N() != 0) {
					xml.startTag("", "C0003_009_02_N");
					xml.text(cap3.getC0003_009_02_N() + "");
					xml.endTag("", "C0003_009_02_N");
				}
				if (cap3.getC0003_009_03_N() != 0) {
					xml.startTag("", "C0003_009_03_N");
					xml.text(cap3.getC0003_009_03_N() + "");
					xml.endTag("", "C0003_009_03_N");
				}

				xml.endTag("", "C0003");
			}

			// CAPITULO 4
			Capitulo4Controller cap4Con = new Capitulo4Controller(context);
			Capitulo4 cap4 = new Capitulo4(RUC, USUARIO);
			cap4 = cap4Con.Cap04Obtener(cap4);
			if (cap4 != null) {
				xml.startTag("", "C0004");
				if (cap4.getC0T01_001_01_T() != null
						&& !cap4.getC0T01_001_01_T().equals("0")) {
					xml.startTag("", "C0T01_001_01_T");
					xml.text(cap4.getC0T01_001_01_T() + "");
					xml.endTag("", "C0T01_001_01_T");
				}
				if (cap4.getC0T01_001_02_T() != null
						&& !cap4.getC0T01_001_02_T().equals("0")) {
					xml.startTag("", "C0T01_001_02_T");
					xml.text(cap4.getC0T01_001_02_T() + "");
					xml.endTag("", "C0T01_001_02_T");
				}
				if (cap4.getC0T01_002_01_T() != null
						&& !cap4.getC0T01_002_01_T().equals("0")
						&& !cap4.getC0T01_002_01_T().equals("")) {
					xml.startTag("", "C0T01_002_01_T");
					xml.text(cap4.getC0T01_002_01_T() + "");
					xml.endTag("", "C0T01_002_01_T");
				}
				if (cap4.getC0T01_003_01_T() != null
						&& !cap4.getC0T01_003_01_T().equals("0")) {
					xml.startTag("", "C0T01_003_01_T");
					xml.text(cap4.getC0T01_003_01_T() + "");
					xml.endTag("", "C0T01_003_01_T");
				}
				if (cap4.getC0T01_003_02_T() != null
						&& !cap4.getC0T01_003_02_T().equals("0")) {
					xml.startTag("", "C0T01_003_02_T");
					xml.text(cap4.getC0T01_003_02_T() + "");
					xml.endTag("", "C0T01_003_02_T");
				}
				if (cap4.getC0T01_004_01_T() != null
						&& !cap4.getC0T01_004_01_T().equals("0")
						&& !cap4.getC0T01_004_01_T().equals("")) {
					xml.startTag("", "C0T01_004_01_T");
					xml.text(cap4.getC0T01_004_01_T() + "");
					xml.endTag("", "C0T01_004_01_T");
				}
				if (cap4.getC0T01_005_01_T() != null
						&& !cap4.getC0T01_005_01_T().equals("0")) {
					xml.startTag("", "C0T01_005_01_T");
					xml.text(cap4.getC0T01_005_01_T() + "");
					xml.endTag("", "C0T01_005_01_T");
				}
				if (cap4.getC0T01_005_02_T() != null
						&& !cap4.getC0T01_005_02_T().equals("0")) {
					xml.startTag("", "C0T01_005_02_T");
					xml.text(cap4.getC0T01_005_02_T() + "");
					xml.endTag("", "C0T01_005_02_T");
				}
				if (cap4.getC0T01_006_01_T() != null
						&& !cap4.getC0T01_006_01_T().equals("0")
						&& !cap4.getC0T01_006_01_T().equals("")) {
					xml.startTag("", "C0T01_006_01_T");
					xml.text(cap4.getC0T01_006_01_T() + "");
					xml.endTag("", "C0T01_006_01_T");
				}
				if (cap4.getC0T01_007_01_T() != null
						&& !cap4.getC0T01_007_01_T().equals("0")) {
					xml.startTag("", "C0T01_007_01_T");
					xml.text(cap4.getC0T01_007_01_T() + "");
					xml.endTag("", "C0T01_007_01_T");
				}
				if (cap4.getC0T01_007_02_T() != null
						&& !cap4.getC0T01_007_02_T().equals("0")) {
					xml.startTag("", "C0T01_007_02_T");
					xml.text(cap4.getC0T01_007_02_T() + "");
					xml.endTag("", "C0T01_007_02_T");
				}
				if (cap4.getC0T01_008_01_T() != null
						&& !cap4.getC0T01_008_01_T().equals("0")
						&& !cap4.getC0T01_008_01_T().equals("")) {
					xml.startTag("", "C0T01_008_01_T");
					xml.text(cap4.getC0T01_008_01_T() + "");
					xml.endTag("", "C0T01_008_01_T");
				}
				if (cap4.getC0T01_009_01_T() != null
						&& !cap4.getC0T01_009_01_T().equals("0")) {
					xml.startTag("", "C0T01_009_01_T");
					xml.text(cap4.getC0T01_009_01_T() + "");
					xml.endTag("", "C0T01_009_01_T");
				}
				if (cap4.getC0T01_009_02_T() != null
						&& !cap4.getC0T01_009_02_T().equals("0")) {
					xml.startTag("", "C0T01_009_02_T");
					xml.text(cap4.getC0T01_009_02_T() + "");
					xml.endTag("", "C0T01_009_02_T");
				}
				if (cap4.getC0T01_010_01_T() != null
						&& !cap4.getC0T01_010_01_T().equals("0")
						&& !cap4.getC0T01_010_01_T().equals("")) {
					xml.startTag("", "C0T01_010_01_T");
					xml.text(cap4.getC0T01_010_01_T() + "");
					xml.endTag("", "C0T01_010_01_T");
				}
				if (cap4.getC0T01_011_01_T() != null
						&& !cap4.getC0T01_011_01_T().equals("0")) {
					xml.startTag("", "C0T01_011_01_T");
					xml.text(cap4.getC0T01_011_01_T() + "");
					xml.endTag("", "C0T01_011_01_T");
				}
				if (cap4.getC0T01_011_02_T() != null
						&& !cap4.getC0T01_011_02_T().equals("0")) {
					xml.startTag("", "C0T01_011_02_T");
					xml.text(cap4.getC0T01_011_02_T() + "");
					xml.endTag("", "C0T01_011_02_T");
				}
				if (cap4.getC0T01_012_01_T() != null
						&& !cap4.getC0T01_012_01_T().equals("0")) {
					xml.startTag("", "C0T01_012_01_T");
					xml.text(cap4.getC0T01_012_01_T() + "");
					xml.endTag("", "C0T01_012_01_T");
				}
				if (cap4.getC0T01_012_02_T() != null
						&& !cap4.getC0T01_012_02_T().equals("0")) {
					xml.startTag("", "C0T01_012_02_T");
					xml.text(cap4.getC0T01_012_02_T() + "");
					xml.endTag("", "C0T01_012_02_T");
				}
				if (cap4.getC0T01_013_01_T() != null
						&& !cap4.getC0T01_013_01_T().equals("0")
						&& !cap4.getC0T01_013_01_T().equals("")) {
					xml.startTag("", "C0T01_013_01_T");
					xml.text(cap4.getC0T01_013_01_T() + "");
					xml.endTag("", "C0T01_013_01_T");
				}
				if (cap4.getC0T01_014_01_T() != null
						&& !cap4.getC0T01_014_01_T().equals("0")
						&& !cap4.getC0T01_014_01_T().equals("")) {
					xml.startTag("", "C0T01_014_01_T");
					xml.text(cap4.getC0T01_014_01_T() + "");
					xml.endTag("", "C0T01_014_01_T");
				}
				if (cap4.getC0T01_015_01_T() != null
						&& !cap4.getC0T01_015_01_T().equals("0")
						&& !cap4.getC0T01_015_01_T().equals("")) {
					xml.startTag("", "C0T01_015_01_T");
					xml.text(cap4.getC0T01_015_01_T() + "");
					xml.endTag("", "C0T01_015_01_T");
				}
				if (cap4.getC0T02_001_01_T() != null
						&& !cap4.getC0T02_001_01_T().equals("0")
						&& !cap4.getC0T02_001_01_T().equals("")) {
					xml.startTag("", "C0T02_001_01_T");
					xml.text(cap4.getC0T02_001_01_T() + "");
					xml.endTag("", "C0T02_001_01_T");
				}
				if (cap4.getC0T02_002_01_T() != null
						&& !cap4.getC0T02_002_01_T().equals("0")) {
					xml.startTag("", "C0T02_002_01_T");
					xml.text(cap4.getC0T02_002_01_T() + "");
					xml.endTag("", "C0T02_002_01_T");
				}
				if (cap4.getC0T02_002_02_T() != null
						&& !cap4.getC0T02_002_02_T().equals("0")) {
					xml.startTag("", "C0T02_002_02_T");
					xml.text(cap4.getC0T02_002_02_T() + "");
					xml.endTag("", "C0T02_002_02_T");
				}
				if (cap4.getC0T02_003_01_T() != null
						&& !cap4.getC0T02_003_01_T().equals("0")) {
					xml.startTag("", "C0T02_003_01_T");
					xml.text(cap4.getC0T02_003_01_T() + "");
					xml.endTag("", "C0T02_003_01_T");
				}
				if (cap4.getC0T02_003_02_T() != null
						&& !cap4.getC0T02_003_02_T().equals("0")) {
					xml.startTag("", "C0T02_003_02_T");
					xml.text(cap4.getC0T02_003_02_T() + "");
					xml.endTag("", "C0T02_003_02_T");
				}
				if (cap4.getC0T02_004_01_T() != null
						&& !cap4.getC0T02_004_01_T().equals("0")
						&& !cap4.getC0T02_004_01_T().equals("")) {
					xml.startTag("", "C0T02_004_01_T");
					xml.text(cap4.getC0T02_004_01_T() + "");
					xml.endTag("", "C0T02_004_01_T");
				}
				if (cap4.getC0T02_005_01_T() != null
						&& !cap4.getC0T02_005_01_T().equals("0")
						&& !cap4.getC0T02_005_01_T().equals("")) {
					xml.startTag("", "C0T02_005_01_T");
					xml.text(cap4.getC0T02_005_01_T() + "");
					xml.endTag("", "C0T02_005_01_T");
				}
				if (cap4.getC0T02_006_01_T() != null
						&& !cap4.getC0T02_006_01_T().equals("")) {
					xml.startTag("", "C0T02_006_01_T");
					xml.text(cap4.getC0T02_006_01_T() + "");
					xml.endTag("", "C0T02_006_01_T");
				}
				if (cap4.getC0T02_007_01_T() != null
						&& !cap4.getC0T02_007_01_T().equals("0")) {
					xml.startTag("", "C0T02_007_01_T");
					xml.text(cap4.getC0T02_007_01_T() + "");
					xml.endTag("", "C0T02_007_01_T");
				}
				if (cap4.getC0T02_007_02_T() != null
						&& !cap4.getC0T02_007_02_T().equals("0")) {
					xml.startTag("", "C0T02_007_02_T");
					xml.text(cap4.getC0T02_007_02_T() + "");
					xml.endTag("", "C0T02_007_02_T");
				}
				if (cap4.getC0T02_008_01_T() != null
						&& !cap4.getC0T02_008_01_T().equals("0")
						&& !cap4.getC0T02_008_01_T().equals("")) {
					xml.startTag("", "C0T02_008_01_T");
					xml.text(cap4.getC0T02_008_01_T() + "");
					xml.endTag("", "C0T02_008_01_T");
				}
				if (cap4.getC0T02_009_01_T() != null
						&& !cap4.getC0T02_009_01_T().equals("0")
						&& !cap4.getC0T02_009_01_T().equals("")) {
					xml.startTag("", "C0T02_009_01_T");
					xml.text(cap4.getC0T02_009_01_T() + "");
					xml.endTag("", "C0T02_009_01_T");
				}
				if (cap4.getC0T02_010_01_T() != null
						&& !cap4.getC0T02_010_01_T().equals("")) {
					xml.startTag("", "C0T02_010_01_T");
					xml.text(cap4.getC0T02_010_01_T() + "");
					xml.endTag("", "C0T02_010_01_T");
				}
				if (cap4.getC0T02_011_01_T() != null
						&& !cap4.getC0T02_011_01_T().equals("0")
						&& !cap4.getC0T02_011_01_T().equals("")) {
					xml.startTag("", "C0T02_011_01_T");
					xml.text(cap4.getC0T02_011_01_T() + "");
					xml.endTag("", "C0T02_011_01_T");
				}
				if (cap4.getC0T03_001_01_T() != null
						&& !cap4.getC0T03_001_01_T().equals("0")) {
					xml.startTag("", "C0T03_001_01_T");
					xml.text(cap4.getC0T03_001_01_T() + "");
					xml.endTag("", "C0T03_001_01_T");
				}
				if (cap4.getC0T03_001_02_T() != null
						&& !cap4.getC0T03_001_02_T().equals("0")) {
					xml.startTag("", "C0T03_001_02_T");
					xml.text(cap4.getC0T03_001_02_T() + "");
					xml.endTag("", "C0T03_001_02_T");
				}
				if (cap4.getC0T03_004_01_T() != null
						&& !cap4.getC0T03_004_01_T().equals("0")) {
					xml.startTag("", "C0T03_004_01_T");
					xml.text(cap4.getC0T03_004_01_T() + "");
					xml.endTag("", "C0T03_004_01_T");
				}
				if (cap4.getC0T03_004_02_T() != null
						&& !cap4.getC0T03_004_02_T().equals("0")) {
					xml.startTag("", "C0T03_004_02_T");
					xml.text(cap4.getC0T03_004_02_T() + "");
					xml.endTag("", "C0T03_004_02_T");
				}
				if (cap4.getC0T03_004_03_T() != null
						&& !cap4.getC0T03_004_03_T().equals("0")) {
					xml.startTag("", "C0T03_004_03_T");
					xml.text(cap4.getC0T03_004_03_T() + "");
					xml.endTag("", "C0T03_004_03_T");
				}
				if (cap4.getC0T03_004_04_T() != null
						&& !cap4.getC0T03_004_04_T().equals("0")) {
					xml.startTag("", "C0T03_004_04_T");
					xml.text(cap4.getC0T03_004_04_T() + "");
					xml.endTag("", "C0T03_004_04_T");
				}
				if (cap4.getC0T03_004_05_T() != null
						&& !cap4.getC0T03_004_05_T().equals("0")) {
					xml.startTag("", "C0T03_004_05_T");
					xml.text(cap4.getC0T03_004_05_T() + "");
					xml.endTag("", "C0T03_004_05_T");
				}
				if (cap4.getC0T03_004_06_T() != null
						&& !cap4.getC0T03_004_06_T().equals("0")) {
					xml.startTag("", "C0T03_004_06_T");
					xml.text(cap4.getC0T03_004_06_T() + "");
					xml.endTag("", "C0T03_004_06_T");
				}
				if (cap4.getC0T03_004_07_T() != null
						&& !cap4.getC0T03_004_07_T().equals("0")) {
					xml.startTag("", "C0T03_004_07_T");
					xml.text(cap4.getC0T03_004_07_T() + "");
					xml.endTag("", "C0T03_004_07_T");
				}
				if (cap4.getC0T03_004_08_T() != null
						&& !cap4.getC0T03_004_08_T().equals("0")) {
					xml.startTag("", "C0T03_004_08_T");
					xml.text(cap4.getC0T03_004_08_T() + "");
					xml.endTag("", "C0T03_004_08_T");
				}
				if (cap4.getC0T03_005_01_T() != null
						&& !cap4.getC0T03_005_01_T().equals("")) {
					xml.startTag("", "C0T03_005_01_T");
					xml.text(cap4.getC0T03_005_01_T() + "");
					xml.endTag("", "C0T03_005_01_T");
				}
				if (cap4.getC0T03_006_01_T() != null
						&& !cap4.getC0T03_006_01_T().equals("0")) {
					xml.startTag("", "C0T03_006_01_T");
					xml.text(cap4.getC0T03_006_01_T() + "");
					xml.endTag("", "C0T03_006_01_T");
				}
				if (cap4.getC0T03_006_02_T() != null
						&& !cap4.getC0T03_006_02_T().equals("0")) {
					xml.startTag("", "C0T03_006_02_T");
					xml.text(cap4.getC0T03_006_02_T() + "");
					xml.endTag("", "C0T03_006_02_T");
				}
				if (cap4.getC0T03_006_03_T() != null
						&& !cap4.getC0T03_006_03_T().equals("0")) {
					xml.startTag("", "C0T03_006_03_T");
					xml.text(cap4.getC0T03_006_03_T() + "");
					xml.endTag("", "C0T03_006_03_T");
				}
				if (cap4.getC0T03_006_04_T() != null
						&& !cap4.getC0T03_006_04_T().equals("0")) {
					xml.startTag("", "C0T03_006_04_T");
					xml.text(cap4.getC0T03_006_04_T() + "");
					xml.endTag("", "C0T03_006_04_T");
				}
				if (cap4.getC0T03_006_05_T() != null
						&& !cap4.getC0T03_006_05_T().equals("0")) {
					xml.startTag("", "C0T03_006_05_T");
					xml.text(cap4.getC0T03_006_05_T() + "");
					xml.endTag("", "C0T03_006_05_T");
				}
				if (cap4.getC0T03_006_06_T() != null
						&& !cap4.getC0T03_006_06_T().equals("0")) {
					xml.startTag("", "C0T03_006_06_T");
					xml.text(cap4.getC0T03_006_06_T() + "");
					xml.endTag("", "C0T03_006_06_T");
				}
				if (cap4.getC0T03_006_07_T() != null
						&& !cap4.getC0T03_006_07_T().equals("0")) {
					xml.startTag("", "C0T03_006_07_T");
					xml.text(cap4.getC0T03_006_07_T() + "");
					xml.endTag("", "C0T03_006_07_T");
				}
				if (cap4.getC0T03_006_08_T() != null
						&& !cap4.getC0T03_006_08_T().equals("0")) {
					xml.startTag("", "C0T03_006_08_T");
					xml.text(cap4.getC0T03_006_08_T() + "");
					xml.endTag("", "C0T03_006_08_T");
				}
				if (cap4.getC0T03_006_09_T() != null
						&& !cap4.getC0T03_006_09_T().equals("0")) {
					xml.startTag("", "C0T03_006_09_T");
					xml.text(cap4.getC0T03_006_09_T() + "");
					xml.endTag("", "C0T03_006_09_T");
				}
				if (cap4.getC0T03_006_10_T() != null
						&& !cap4.getC0T03_006_10_T().equals("0")) {
					xml.startTag("", "C0T03_006_10_T");
					xml.text(cap4.getC0T03_006_10_T() + "");
					xml.endTag("", "C0T03_006_10_T");
				}
				if (cap4.getC0T03_007_01_T() != null
						&& !cap4.getC0T03_007_01_T().equals("")) {
					xml.startTag("", "C0T03_007_01_T");
					xml.text(cap4.getC0T03_007_01_T() + "");
					xml.endTag("", "C0T03_007_01_T");
				}
				if (cap4.getC0T03_008_01_T() != null
						&& !cap4.getC0T03_008_01_T().equals("")) {
					xml.startTag("", "C0T03_008_01_T");
					xml.text(cap4.getC0T03_008_01_T() + "");
					xml.endTag("", "C0T03_008_01_T");
				}
				if (cap4.getC0T04_001_01_T() != null
						&& !cap4.getC0T04_001_01_T().equals("0")) {
					xml.startTag("", "C0T04_001_01_T");
					xml.text(cap4.getC0T04_001_01_T() + "");
					xml.endTag("", "C0T04_001_01_T");
				}
				if (cap4.getC0T04_001_02_T() != null
						&& !cap4.getC0T04_001_02_T().equals("0")) {
					xml.startTag("", "C0T04_001_02_T");
					xml.text(cap4.getC0T04_001_02_T() + "");
					xml.endTag("", "C0T04_001_02_T");
				}
				if (cap4.getC0T04_002_01_T() != null
						&& !cap4.getC0T04_002_01_T().equals("0")) {
					xml.startTag("", "C0T04_002_01_T");
					xml.text(cap4.getC0T04_002_01_T() + "");
					xml.endTag("", "C0T04_002_01_T");
				}
				if (cap4.getC0T04_002_02_T() != null
						&& !cap4.getC0T04_002_02_T().equals("0")) {
					xml.startTag("", "C0T04_002_02_T");
					xml.text(cap4.getC0T04_002_02_T() + "");
					xml.endTag("", "C0T04_002_02_T");
				}
				if (cap4.getC0T04_003_01_T() != null
						&& !cap4.getC0T04_003_01_T().equals("0")) {
					xml.startTag("", "C0T04_003_01_T");
					xml.text(cap4.getC0T04_003_01_T() + "");
					xml.endTag("", "C0T04_003_01_T");
				}
				if (cap4.getC0T04_003_02_T() != null
						&& !cap4.getC0T04_003_02_T().equals("0")) {
					xml.startTag("", "C0T04_003_02_T");
					xml.text(cap4.getC0T04_003_02_T() + "");
					xml.endTag("", "C0T04_003_02_T");
				}
				if (cap4.getC0T04_004_01_T() != null
						&& !cap4.getC0T04_004_01_T().equals("0")) {
					xml.startTag("", "C0T04_004_01_T");
					xml.text(cap4.getC0T04_004_01_T() + "");
					xml.endTag("", "C0T04_004_01_T");
				}
				if (cap4.getC0T04_004_02_T() != null
						&& !cap4.getC0T04_004_02_T().equals("0")) {
					xml.startTag("", "C0T04_004_02_T");
					xml.text(cap4.getC0T04_004_02_T() + "");
					xml.endTag("", "C0T04_004_02_T");
				}
				if (cap4.getC0T04_005_01_T() != null
						&& !cap4.getC0T04_005_01_T().equals("0")) {
					xml.startTag("", "C0T04_005_01_T");
					xml.text(cap4.getC0T04_005_01_T() + "");
					xml.endTag("", "C0T04_005_01_T");
				}
				if (cap4.getC0T04_005_02_T() != null
						&& !cap4.getC0T04_005_02_T().equals("0")) {
					xml.startTag("", "C0T04_005_02_T");
					xml.text(cap4.getC0T04_005_02_T() + "");
					xml.endTag("", "C0T04_005_02_T");
				}

				xml.endTag("", "C0004");
			}

			// ENTREVISTA
			EntrevistaController entCon = new EntrevistaController(context);
			Entrevista ent = new Entrevista(RUC, USUARIO);
			List<Entrevista> lEnt = entCon.EntrevistaObtener(ent);
			if (lEnt != null) {
				xml.startTag("", "C0024");
				for (int i = 0; i < lEnt.size(); i++) {
					if (lEnt.get(i).getC0024_000_01_T() != null) {
						xml.startTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_01_T");
						xml.text(lEnt.get(i).getC0024_000_01_T());
						xml.endTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_01_T");
					}
					if (lEnt.get(i).getC0024_000_02_T() != null) {
						xml.startTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_02_T");
						xml.text(lEnt.get(i).getC0024_000_02_T());
						xml.endTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_02_T");
					}
					if (lEnt.get(i).getC0024_000_03_T() != null) {
						xml.startTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_03_T");
						xml.text(lEnt.get(i).getC0024_000_03_T());
						xml.endTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_03_T");
					}
					if (lEnt.get(i).getC0024_000_04_T() != null) {
						xml.startTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_04_T");
						xml.text(lEnt.get(i).getC0024_000_04_T());
						xml.endTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_04_T");
					}
					if (lEnt.get(i).getC0024_000_05_T() != null) {
						xml.startTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_05_T");
						xml.text(lEnt.get(i).getC0024_000_05_T());
						xml.endTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_05_T");
					}
					if (lEnt.get(i).getC0024_000_06_T() != null) {
						xml.startTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_06_T");
						xml.text(lEnt.get(i).getC0024_000_06_T());
						xml.endTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_06_T");
					}
					if (lEnt.get(i).getGPS_LAT() != null) {
						xml.startTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_GPS_LAT");
						xml.text(lEnt.get(i).getGPS_LAT());
						xml.endTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_GPS_LAT");
					}
					if (lEnt.get(i).getGPS_LON() != null) {
						xml.startTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_GPS_LON");
						xml.text(lEnt.get(i).getGPS_LON());
						xml.endTag("", "C0024_0"
								+ (lEnt.get(i).getNRO_ENT() < 10 ? ("0" + lEnt
										.get(i).getNRO_ENT()) : lEnt.get(i)
										.getNRO_ENT()) + "_GPS_LON");
					}
				}
				xml.endTag("", "C0024");
			}

			// JUSTIFICACION
			JustificacionController jusCon2 = new JustificacionController(
					context);
			Justificacion jus2 = new Justificacion(RUC, USUARIO, "2");
			List<Justificacion> lJus2 = jusCon2
					.JustificacionObtenerPorRuc(jus2);
			JustificacionController jusCon3 = new JustificacionController(
					context);
			Justificacion jus3 = new Justificacion(RUC, USUARIO, "3");
			List<Justificacion> lJus3 = jusCon3
					.JustificacionObtenerPorRuc(jus3);

			xml.startTag("", "C0JUS");
			if (lJus2 != null) {
				if (lJus2.get(0).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_001_01_N");
					xml.text(lJus2.get(0).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_001_01_N");

					// xml.startTag("", "C0JUS_001_02_N");
					// xml.text(lJus2.get(0).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_001_02_N");

					xml.startTag("", "C0JUS_001_03_N");
					xml.text(lJus2.get(0).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_001_03_N");

					xml.startTag("", "C0JUS_001_04_N");
					xml.text(lJus2.get(0).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_001_04_N");
				}

				if (lJus2.get(1).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_002_01_N");
					xml.text(lJus2.get(1).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_002_01_N");

					// xml.startTag("", "C0JUS_002_02_N");
					// xml.text(lJus2.get(1).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_002_02_N");

					xml.startTag("", "C0JUS_002_03_N");
					xml.text(lJus2.get(1).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_002_03_N");

					xml.startTag("", "C0JUS_002_04_N");
					xml.text(lJus2.get(1).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_002_04_N");
				}

				if (lJus2.get(2).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_003_01_N");
					xml.text(lJus2.get(2).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_003_01_N");

					// xml.startTag("", "C0JUS_003_02_N");
					// xml.text(lJus2.get(2).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_003_02_N");

					xml.startTag("", "C0JUS_003_03_N");
					xml.text(lJus2.get(2).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_003_03_N");

					xml.startTag("", "C0JUS_003_04_N");
					xml.text(lJus2.get(2).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_003_04_N");
				}

				if (lJus2.get(3).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_004_01_N");
					xml.text(lJus2.get(3).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_004_01_N");

					// xml.startTag("", "C0JUS_004_02_N");
					// xml.text(lJus2.get(3).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_004_02_N");

					xml.startTag("", "C0JUS_004_03_N");
					xml.text(lJus2.get(3).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_004_03_N");

					xml.startTag("", "C0JUS_004_04_N");
					xml.text(lJus2.get(3).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_004_04_N");
				}

				if (lJus2.get(4).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_005_01_N");
					xml.text(lJus2.get(4).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_005_01_N");

					// xml.startTag("", "C0JUS_005_02_N");
					// xml.text(lJus2.get(4).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_005_02_N");

					xml.startTag("", "C0JUS_005_03_N");
					xml.text(lJus2.get(4).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_005_03_N");

					xml.startTag("", "C0JUS_005_04_N");
					xml.text(lJus2.get(4).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_005_04_N");
				}

				if (lJus2.get(5).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_006_01_N");
					xml.text(lJus2.get(5).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_006_01_N");

					// xml.startTag("", "C0JUS_006_02_N");
					// xml.text(lJus2.get(5).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_006_02_N");

					xml.startTag("", "C0JUS_006_03_N");
					xml.text(lJus2.get(5).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_006_03_N");

					xml.startTag("", "C0JUS_006_04_N");
					xml.text(lJus2.get(5).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_006_04_N");
				}

				if (lJus2.get(6).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_007_01_N");
					xml.text(lJus2.get(6).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_007_01_N");

					// xml.startTag("", "C0JUS_007_02_N");
					// xml.text(lJus2.get(6).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_007_02_N");

					xml.startTag("", "C0JUS_007_03_N");
					xml.text(lJus2.get(6).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_007_03_N");

					xml.startTag("", "C0JUS_007_04_N");
					xml.text(lJus2.get(6).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_007_04_N");
				}

				if (lJus2.get(7).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_008_01_N");
					xml.text(lJus2.get(7).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_008_01_N");

					// xml.startTag("", "C0JUS_008_02_N");
					// xml.text(lJus2.get(7).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_008_02_N");

					xml.startTag("", "C0JUS_008_03_N");
					xml.text(lJus2.get(7).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_008_03_N");

					xml.startTag("", "C0JUS_008_04_N");
					xml.text(lJus2.get(7).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_008_04_N");
				}

				if (lJus2.get(8).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_009_01_N");
					xml.text(lJus2.get(8).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_009_01_N");

					// xml.startTag("", "C0JUS_009_02_N");
					// xml.text(lJus2.get(8).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_009_02_N");

					xml.startTag("", "C0JUS_009_03_N");
					xml.text(lJus2.get(8).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_009_03_N");

					xml.startTag("", "C0JUS_009_04_N");
					xml.text(lJus2.get(8).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_009_04_N");
				}

				if (lJus2.get(9).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_010_01_N");
					xml.text(lJus2.get(9).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_010_01_N");

					// xml.startTag("", "C0JUS_010_02_N");
					// xml.text(lJus2.get(9).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_010_02_N");

					xml.startTag("", "C0JUS_010_03_N");
					xml.text(lJus2.get(9).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_010_03_N");

					xml.startTag("", "C0JUS_010_04_N");
					xml.text(lJus2.get(9).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_010_04_N");
				}
			}
			if (lJus3 != null) {
				if (lJus3.get(0).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_011_01_N");
					xml.text(lJus3.get(0).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_011_01_N");

					// xml.startTag("", "C0JUS_011_02_N");
					// xml.text(lJus3.get(0).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_011_02_N");

					xml.startTag("", "C0JUS_011_03_N");
					xml.text(lJus3.get(0).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_011_03_N");

					xml.startTag("", "C0JUS_011_04_N");
					xml.text(lJus3.get(0).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_011_04_N");
				}

				if (lJus3.get(1).getC0JUS_001_03_N().length() != 0) {
					xml.startTag("", "C0JUS_012_01_N");
					xml.text(lJus3.get(1).getC0JUS_001_01_N());
					xml.endTag("", "C0JUS_012_01_N");

					// xml.startTag("", "C0JUS_012_02_N");
					// xml.text(lJus3.get(1).getC0JUS_001_02_N());
					// xml.endTag("", "C0JUS_012_02_N");

					xml.startTag("", "C0JUS_012_03_N");
					xml.text(lJus3.get(1).getC0JUS_001_03_N());
					xml.endTag("", "C0JUS_012_03_N");

					xml.startTag("", "C0JUS_012_04_N");
					xml.text(lJus3.get(1).getC0JUS_001_04_N());
					xml.endTag("", "C0JUS_012_04_N");
				}
			}
			xml.endTag("", "C0JUS");

			xml.endTag("", "script");
			xml.endDocument();
			fos.close();

		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
}
